﻿using AmiDraw.Editor.Factory;
using AmiDraw.Editor.ViewModel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AmiDraw.Editor
{
    public class CommonOperateHelper
    {
        public static bool ImportImage(object obj, out string file)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == true)
            {
                file = dialog.FileName;
                if (ResFactory.ImportImageToProject(file, PackEditViewModel.instance.PackInfo.Name) is false)
                {
                    if (MessageBox.Show("文件存在，是否替换？", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        ResFactory.ImportImageToProject(file, PackEditViewModel.instance.PackInfo.Name, true);
                        MessageBox.Show("添加成功");
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    MessageBox.Show("添加成功");
                }

                return true;
            }

            file = "";
            return false;
        }
    }
}